//
//  AuthenicateCommunityCell.m
//  QRMaster
//
//  Created by myApple on 16/4/11.
//  Copyright © 2016年 myApple. All rights reserved.
//

#import "AuthenicateCommunityCell.h"

@interface AuthenicateCommunityCell()
{
    UILabel * titleLabel;
    UILabel * titleInfoLabel;
    UIImageView * instructImageView;
    UIImageView * authenImageView;
}
@end

@implementation AuthenicateCommunityCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self prepareView];
       
    }
    return self;
}

-(void)prepareView
{
    float x = 16;
    float y = 20;
    float width = 100;
    float height = 20;

    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    titleLabel.font = [UIFont systemFontOfSize:16.0];
    titleLabel.textColor = UIColorFromRGB(0x333333);
    [self.contentView addSubview:titleLabel];
    
    x = UI_SCREEN_WIDTH - 210;
    width = 170;
    titleInfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    titleInfoLabel.font = [UIFont systemFontOfSize:15.0];
    titleInfoLabel.textColor = UIColorFromRGB(0xc1c1c1);
    titleInfoLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:titleInfoLabel];
    
    x += width + 16;
    y = 24;
    height = 12;
    width = 8;
    instructImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, width, height)];
    instructImageView.image = [UIImage imageNamed:@"nextIndicate"];
    [self.contentView addSubview:instructImageView];
    
    
    
    x = UI_SCREEN_WIDTH - 105;
    y = titleInfoLabel.frame.origin.y + 2;
    width = 12.5;
    height = 15;
    authenImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, width, height)];
    authenImageView.image = [UIImage imageNamed:@"authenImage"];
    [self.contentView addSubview:authenImageView];
    authenImageView.hidden = YES;
    
}

-(void)setTitleName:(NSString *)titleName
{
    _titleName = titleName;
    titleLabel.text = titleName;
}

-(void)setContentString:(NSString *)contentString
{
    _contentString = contentString;
    titleInfoLabel.text = contentString;
}

-(void)setHasInstruct:(BOOL)hasInstruct
{
    _hasInstruct = hasInstruct;
    if (_hasInstruct) {
        instructImageView.hidden = NO;
    }
    else
    {
        instructImageView.hidden = YES;
    }
}

-(void)setIsShowImage:(BOOL)isShowImage
{
    if (isShowImage) {
        authenImageView.hidden = NO;
        authenImageView.frame = CGRectMake(UI_SCREEN_WIDTH - [self calculateWidth:titleInfoLabel.text] - 50 - authenImageView.frame.size.width, authenImageView.frame.origin.y, authenImageView.frame.size.width, authenImageView.frame.size.height);
    }
    else
    {
        authenImageView.hidden = YES;
    }
}

-(void)setAuthenColor:(UIColor *)authenColor
{
    _authenColor = authenColor;
    titleInfoLabel.textColor = authenColor;
}

#pragma mark --------  自适应lable的长度
-(float)calculateWidth:(NSString *)str
{
     NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
    CGSize textSize = [str boundingRectWithSize:CGSizeMake(200, 20) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
    float width = textSize.width;
    return width;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
